<link rel="stylesheet" href="__CDN__/assets/element-ui-2.15.14/css/index.css">
<link rel="stylesheet" href="__CDN__/assets/css/vvv.css">
<style>
    .el-form-item__label {
        width: 120px !important;
    }

    .el-tag + .el-tag {
        margin-left: 10px;
    }

    .button-new-tag {
        margin-left: 10px;
        height: 32px;
        line-height: 30px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .input-new-tag {
        width: 90px;
        margin-left: 10px;
        vertical-align: bottom;
    }

    input[type="file"] {
        display: none !important;
    }

    .el-form-item__error {
        margin-left: 30px;
    }

    .search-select .el-input--suffix .el-input__inner {
        width: 130px;
    }
</style>
<div id="vue" v-cloak>
    <div class="screen-container">
        <div class="screen-container-show">
            <div class="screen-container-right display-flex keyword">
                <el-button @click="openAddDialog('add', '')" size="small" type="primary" plain icon="el-icon-plus">添加
                </el-button>
            </div>
        </div>
    </div>
    <div class="vue-table background-white color-666">
        <el-table :data="tableData" border highlight-current-row v-loading="listLoading"
                  @sort-change="sortChange" element-loading-text="拼命加载中..."
                  @selection-change="handleSelectionChange"
                  :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
                  row-key="id"
                  style="width: 100%">
            <el-table-column prop="id" width="120" label="编号" show-overflow-tooltip
                             align="center"></el-table-column>
            <el-table-column prop="name" label="名称" show-overflow-tooltip
                             align="center"></el-table-column>
            <el-table-column prop="sort" width="120" label="排序" show-overflow-tooltip
                             align="center"></el-table-column>
            <el-table-column prop="status" width="170" label="分类状态" show-overflow-tooltip
                             align="center">
                <template scope="scope">
                    <el-switch
                            active-text="启用"
                            inactive-text="禁用"
                            v-model="scope.row.status"
                            :active-value="1"
                            :inactive-value="2"
                            @change="handleStatusChange(scope.row)"
                    >
                    </el-switch>
                </template>
            </el-table-column>
            <el-table-column prop="create_time" width="160" :formatter="dateFormat" label="创建时间" show-overflow-tooltip
                             align="center"></el-table-column>
            <el-table-column align="center" width="220" fixed="right" label="操作">
                <template scope="scope">
                    <button @click="openAddDialog('edit', scope.row)" type="button"
                            class="el-button el-button--primary el-button--small"><i
                            class="el-icon-edit"></i><span>编辑</span></button>
                    <button @click="dell(scope.row.id)" type="button"
                            class="el-button el-button--danger el-button--small"><i
                            class="el-icon-delete"></i><span>删除</span></button>
                </template>
            </el-table-column>
        </el-table>
        <div class="layout-pagination">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-sizes="[10, 20, 50, 100]"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalCount">
            </el-pagination>
        </div>
    </div>

    <!-- 添加编辑 -->
    <div class="nav-dialog">
        <el-dialog
                :close-on-click-modal="false"
                :title="title"
                :visible.sync="addDialog"
                width="50%"
        >
            <div class="form">
                <el-form ref="form" :rules="rules" :model="formData" label-width="90px">
                    <el-form-item label="所属上级：" prop="pid">
                        <el-select style="width: 330px;" v-model="formData.pid" clearable filterable placeholder="所属上级，不选择则为顶级。">
                            <el-option
                                    v-for="item in tableData"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="名称：" prop="name">
                        <el-input style="width: 330px;" show-word-limit :maxlength="50" v-model="formData.name"></el-input>
                    </el-form-item>
                    <el-form-item label="排序：" prop="sort">
                        <el-input style="width: 330px;"  type="number" v-model="formData.sort"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用：" prop="status">
                        <el-radio style="margin-right: 0;" v-model="formData.status" label="1" border size="small">是
                        </el-radio>
                        <el-radio v-model="formData.status" label="2" border size="small">否</el-radio>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addDialog = false" size="small" icon="el-icon-switch-button">取 消</el-button>
                <el-button type="primary" size="small" @click="submit" icon="el-icon-position">提 交</el-button>
            </span>
        </el-dialog>
    </div>
</div>

<script src="__CDN__/assets/element-ui-2.15.14/js/vue.js"></script>
<script src="__CDN__/assets/element-ui-2.15.14/js/index.js"></script>
<script src="__CDN__/assets/tool/libs/moment.js"></script>
<script src="__CDN__/assets/js/jquery-2.1.1.min.js"></script>